package com.academic_system.util;

/**
 * @author 20155883 万珊
 * @description
 * @project_name
 * @package
 * @create 2018-06-08 22:09
 **/
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
/**
 * 测试发送短信
 *
 * @author zrz
 */
public class aa {
    public static void main(String[] args) throws Exception {
        HttpClient client = new HttpClient();
        PostMethod post = new PostMethod("http://utf8.sms.webchinese.cn/");
        post.addRequestHeader("Content-Type",
                "application/x-www-form-urlencoded;charset=ISO-8859-1");// 在头文件中设置转码
        NameValuePair[] data = { new NameValuePair("Uid", "wshan0117"),
                new NameValuePair("Key", "d41d8cd98f00b204e980"),
                new NameValuePair("smsMob", "15202285968"),
                new NameValuePair("smsText", "wanshan接收：手机验证码：12451597474") };
        post.setRequestBody(data);

        client.executeMethod(post);
        Header[] headers = post.getResponseHeaders();
        int statusCode = post.getStatusCode();
        System.out.println("statusCode:" + statusCode);
        for (Header h : headers) {
            System.out.println(h.toString());
        }
        String result = new String(post.getResponseBodyAsString().getBytes(
                "gbk"));
        System.out.println(result);

        post.releaseConnection();
    }
}
